package com.ruoyi.web.controller.useradditionalinfo;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.UserAdditionalInfo;
import com.ruoyi.system.service.IUserAdditionalInfoService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 小程序用户额外信息Controller
 * 
 * @author chen
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/useradditionalinfo/info")
@Tag(name = "【小程序用户额外信息】管理")
public class UserAdditionalInfoController extends BaseController
{
    @Autowired
    private IUserAdditionalInfoService userAdditionalInfoService;

    /**
     * 查询小程序用户额外信息列表
     */
    @Operation(summary = "查询小程序用户额外信息列表")
    @GetMapping("/list")
    public TableDataInfo list(UserAdditionalInfo userAdditionalInfo)
    {
        startPage();
        List<UserAdditionalInfo> list = userAdditionalInfoService.selectUserAdditionalInfoList(userAdditionalInfo);
        return getDataTable(list);
    }

    /**
     * 导出小程序用户额外信息列表
     */
    @Operation(summary = "导出小程序用户额外信息列表")
    @Log(title = "小程序用户额外信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserAdditionalInfo userAdditionalInfo)
    {
        List<UserAdditionalInfo> list = userAdditionalInfoService.selectUserAdditionalInfoList(userAdditionalInfo);
        ExcelUtil<UserAdditionalInfo> util = new ExcelUtil<UserAdditionalInfo>(UserAdditionalInfo.class);
        util.exportExcel(response, list, "小程序用户额外信息数据");
    }

    /**
     * 获取小程序用户额外信息详细信息
     */
    @Operation(summary = "获取小程序用户额外信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userAdditionalInfoService.selectUserAdditionalInfoById(id));
    }

    /**
     * 获取小程序用户额外信息详细信息
     */
    @Operation(summary = "获取小程序用户额外信息详细信息")
    @GetMapping(value = "/byUserId/{userId}")
    public AjaxResult getInfoByUserId(@PathVariable Long userId)
    {
        return success(userAdditionalInfoService.selectUserAdditionalInfoByUserId(userId));
    }

    /**
     * 新增小程序用户额外信息
     */
    @Operation(summary = "新增小程序用户额外信息")
    @Log(title = "小程序用户额外信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAdditionalInfo userAdditionalInfo)
    {
        return toAjax(userAdditionalInfoService.insertUserAdditionalInfo(userAdditionalInfo));
    }

    /**
     * 修改小程序用户额外信息
     */
    @Operation(summary = "修改小程序用户额外信息")
    @Log(title = "小程序用户额外信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserAdditionalInfo userAdditionalInfo)
    {
        return toAjax(userAdditionalInfoService.updateUserAdditionalInfo(userAdditionalInfo));
    }

    /**
     * 删除小程序用户额外信息
     */
    @Operation(summary = "删除小程序用户额外信息")
    @Log(title = "小程序用户额外信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) 
    {
        return toAjax(userAdditionalInfoService.deleteUserAdditionalInfoByIds(ids));
    }

    /**
     * 获取用户积分排行榜
     */
    @Operation(summary = "获取用户积分排行榜")
    @GetMapping("/listPointsRank")
    public TableDataInfo listPointsRank(UserAdditionalInfo userAdditionalInfo)
    {
        startPage();
        List<UserAdditionalInfo> list = userAdditionalInfoService.selectUserPointsRank(userAdditionalInfo);
        return getDataTable(list);
    }
}
